{template 'common/header'}
<title>签约加盟支付</title>
<style type="text/css">
    body {margin:0px; background:#efefef; font-family:'微软雅黑'; -moz-appearance:none;}
.order_main {height:auto; border-bottom:1px solid #f0f0f0; border-top:1px solid #f0f0f0; background:#fff;margin-top:10px;}
.order_main .line {height:44px; margin:0 5px; border-bottom:1px solid #f0f0f0; line-height:44px;}
.order_main .line .label { float:left;width:80px;}
.order_main .line .info { float:right; width:100%; margin-left:-85px;text-align: right;overflow:hidden;height:44px;}
.order_main .line .info .inner { color:#666;margin-left:85px;}
.order_main .tip { color:#666; line-height:20px;padding:5px;font-size:13px; }
 
  .order_main .line .nav {height:22px; width:40px; background:#ccc; margin:10px 0px; float:right; border-radius:40px;}
.order_main .line .on {background:#4ad966;}
.order_main .line .nav nav {height:20px; width:20px; background:#fff; margin:1px; border-radius:20px;}
.order_main .line .nav .on {margin-left:19px;}

.order_sub1 {height:44px; margin:14px 5px; background:#31cd00; border-radius:4px; text-align:center; font-size:16px; line-height:44px; color:#fff;}
.order_sub2 {height:44px; margin:14px 5px; background:#f49c06; border-radius:4px; text-align:center; font-size:16px; line-height:44px; color:#fff;}
.order_sub3 {height:44px; margin:14px 5px;background:#e2cb04; border-radius:4px; text-align:center; font-size:16px; line-height:44px; color:#fff;}
.order_sub4 {height:44px; margin:14px 5px; background:#18c0f7; border-radius:4px; text-align:center; font-size:16px; line-height:44px; color:#fff;}

.order_main1 {height:30px;padding:10px;border-bottom:1px solid #f0f0f0; border-top:1px solid #f0f0f0; background:#fff;text-align:center;margin-top:10px; }
.order_sub5 {height:30px; width:35%;padding:5px 10px 5px 10px; border:1px solid #ccc; border-radius:4px; text-align:center; font-size:16px; line-height:30px; color:#333; }
.order_sub6 {height:44px; margin:14px 5px; background:#07c4d0; border-radius:4px; text-align:center; font-size:16px; line-height:44px; color:#fff;}
.order_sub7 {height:44px; margin:14px 5px; background:#07c4d0; border-radius:4px; text-align:center; font-size:16px; line-height:44px; color:#fff;}

.order_subc {height:44px; margin:14px 5px; background:#31cd00; border-radius:4px; text-align:center; font-size:16px; line-height:44px; color:#fff;}

</style>
<div id='container'></div>
<script id='tpl_order_info' type='text/html'>
    <input type='hidden' id='orderid' value="<%order.id%>"/>
       <div class="page_topbar">
        <a href="javascript:;" class="back" onclick="history.back()"><i class="fa fa-angle-left"></i></a>
        <div class="title">签约加盟支付</div>
    </div>
    <div class="order_main" >  
        <div class="line" style="display:none;"><div class="label">订单编号</div><div class="info"><div class="inner"><%order.ordersn%></div></div></div>
        <div class="line"><div class="label">支付金额</div><div class="info"><div class="inner"><div style='color:#ff6600'>￥<span id="orderprice" price="<%order.price%>"><%if order.price<0%>0.00<%/if%><%if order.price>=0%><%order.price%><%/if%></span>元</div></div></div></div>
    </div>
    <%if order.price>0%>    
    <%if wechat.success%><div class="button order_sub1">微信支付</div><%/if%>
    <!--<%if unionpay.success%><div class="button order_sub7" >银联支付</div><%/if%>
         <%if alipay.success%><div class="button order_sub2" >支付宝支付</div><%/if%>-->
      <%if member.dongyu != 1%>
    	<%if credit.success%>
              <%if  credit.current-order.price>=0%>
        	<div class="button order_sub3">余额支付(当前余额:<%credit.current%>)</div>
        	<input type="hidden" id="credit" value="<%credit.current%>" /> 
              <%/if%>
    	<%/if%>
      <%/if%>
    <%/if%>
    <!--<div class="button order_subc"  <%if order.price>0%>style="display:none"<%/if%>>确认支付</div>
    <%if cash.success%><div class="button order_sub6" >货到付款</div><%/if%>-->
</script>

<script id='tpl_order_pay' type='text/html'>
<style type="text/css">
body {margin:0px; background:#fff;}
.top {height:68px; background:#fff; border-bottom:#e3e3e3; overflow:hidden;}
.top .ico {height:44px; width:44px; margin:12px; background:#fe9900; border-radius:44px; font-size:30px; line-height:44px; text-align:center; color:#fff; float:left;}
.top .info1 {height:44px; padding:12px 0px; float:left;}
.top .info1 .t1 {height:22px; font-size:16px; color:#666; line-height:26px;}
.top .info1 .t2 {height:22px; font-size:13px; color:#999; line-height:20px;}
.top span {color:#ff6600}
.img {padding:1px;overflow:hidden;height:auto;padding-top:2px;}
.img img { width:80%;margin-left:10%;margin-right:10%;}

.info {height:auto; background:#fff; padding:10px; padding-bottom:80px; border-bottom:1px solid #eee; border-top:1px solid #eee;}
.info .title {height:38px; border-bottom:1px solid #eee; overflow:hidden;}
.info .title .ico {height:24px; width:24px; background:#fd6401; margin:7px 7px 7px 0px; border-radius:24px; font-size:12px; color:#fff; line-height:24px; text-align:center; float:left;}
.info .title .text {height:38px; line-height:38px; font-size:14px; color:#666; float:left;}
.info .con {height:auto; padding:10px 0px;}
.info .con .line {height:auto; overflow:hidden; margin-bottom:5px;}
.info .con .line .t1 {height:auto; width:55px; float:left; font-size:14px; color:#666; line-height:20px;}
.info .con .line .t2 {padding-left:0px; background:#f90;}
.info .con .line .t2 .t3 {height:auto; float:left; font-size:14px; color:#999;}
.info .info2 {height:auto; background:#fe924a; padding:10px; font-size:14px; color:#fff;}

.bottom {height:50px; width:100%; background:#fff; padding:10px; border-top:1px solid #eee; position:fixed; bottom:0px; left:0px; box-shadow:1px 2px 10px rgba(0,0,0,0.2);}
.bottom .sub {height:50px; width:46%; margin-left:2%; float:left; border:1px solid #eee; border-radius:3px; font-size:16px; line-height:50px; text-align:center; color:#666;}
.zhuanshu {text-align:center;font-size:18px;color:#666;background:#fff;padding-top:10px}
.erweima {text-align:center;font-size:18px;background:#fff;padding-top:5px}

</style> 
	<div class="erweima">恭喜支付成功！请等待审核...</div>
    <!-- 系统生成图片 开始 -->
    <div class="img">
        <img id='posterimg' src="../addons/ewei_shop/template/mobile/default/static/images/xiaoyaotubiao.jpg" />
    </div>
    <!-- 系统生成图片 结束 -->
	<div class="info">
        <div class="con">
          <div class="line">
          	<div class="t2">
            	<div class="t3">
                    1.有任何问题可以后台咨询客服（客服微信：lanxuevip2016）
                </div>
          	</div>
          </div>
          <div class="line">
          	<div class="t2">
            	<div class="t3">2.我们将为您提供各种加盟支持，更多权益在个人中心—加盟中心查看。</div>
          	</div>
          </div>
  	    </div>
	</div>
</script>

<script id='tpl_order_cash' type='text/html'>
	<div class="erweima">恭喜支付成功！请等待审核...</div>
    <!-- 系统生成图片 开始 -->
    <div class="img">
        <img id='posterimg' src="../addons/ewei_shop/template/mobile/default/static/images/xiaoyaotubiao.jpg" />
    </div>
    <!-- 系统生成图片 结束 -->
	<div class="info">
        <div class="con">
          <div class="line">
          	<div class="t2">
            	<div class="t3">
                    1.有任何问题可以后台咨询客服（客服微信：lanxuevip2016）
                </div>
          	</div>
          </div>
          <div class="line">
          	<div class="t2">
            	<div class="t3">2.我们将为您提供各种加盟支持，更多权益在个人中心—加盟中心查看。</div>
          	</div>
          </div>
  	    </div>
	</div>
</script>


 <style type="text/css">
.pop-dialog {position: fixed;top: 0;left: 0;width: 100%;height: 100%;z-index: 999;display: none;}
.pop-dialog .bg {width: 100%;height: 100%;position: absolute;top: 0;left: 0;opacity: 0.9;background-color: #000;}
.pop-dialog .body {position: absolute;top: 0;right: 10%;width: 80%;padding-top: 46px;color: #fff;}
.pop-dialog .body > p {line-height: 1.4;font-size: 14px;padding: 6px 0;}
.pop-dialog .body img.icon {width: 36px;margin: 0 5px;display: inline-block;}
.pop-dialog .body img.arrow {position: absolute;right: -10%;top: 0;display: block;margin-right: -13px;width: 70px;}
i.icon {padding: 4px 12px;margin: 0 3px;border-radius: 3px;background-color: #3b3b3b;font-size: 14px;}
a.btn {background-color: #3b3b3b;color: #fff;margin-top:15px;display: block;margin: 0 auto;padding: 10px 20px;border-radius: 3px;text-align: center;text-decoration: none;font-size: 16px;}
</style>
  
<div class="pop-dialog" onclick="$(this).hide();">
    <div class="bg"></div>
    <div class="body">
        <img class="arrow" src="../addons/ewei_shop/template/mobile/default/static/images/arrow.png">
        <p>1. 点击右上角 <i class="fa fa-ellipsis-h"></i> 或 <i class="fa fa-ellipsis-v"></i></p>
        <p>2. 由于在微信中无法打开支付宝付款页面，请选择在浏览器中打开，即可访问购买页面</p>
       
       <p>3. 付款成功后，请返回到这里点击下面的返回按钮</p>
       <a href="{php echo $this->createMobileUrl('order/detail',array('id'=>$_GPC['orderid']))}" class="btn">返回</a>&nbsp;
         
    </div>
</div>

<script language="javascript">
 function isWeiXin(){ 
        var ua = window.navigator.userAgent.toLowerCase(); 
        if(ua.match(/MicroMessenger/i) == 'micromessenger'){ 
            return true; 
        }else{ 
            return false; 
        } 
    }

    require(['tpl', 'core'], function(tpl, core) {
        core.json('order/pay',{franchise_order_id:'{$_GPC['franchise_order_id']}',openid:"{$openid}"},function(json){
            var result = json.result;
            if(json.status==-1){
                 //location.href = core.getUrl('shop/apply');
                 return;
            }
            if(json.status!=1){
                 //core.message(result,"{php echo $this->createMobileUrl('shop/apply')}",'error');
                 return;
            }
            $('#container').html(tpl('tpl_order_info',result));
            
           if(result.alipay.success){
 
                 $('.order_sub2').click(function(){
                     if( isWeiXin() ) {
                       $('.pop-dialog').show();
                       return;
                     }
                     var deduct = ($('#deductmoney').length>0 &&$('#deductmoney').attr('on')=='1' )?1:0 ;
                    core.json('order/pay', {op: 'pay',type: 'alipay', franchise_order_id:'{$_GPC['franchise_order_id']}',openid:"{$openid}",deduct:deduct}, function (rjson) {
                        if(rjson.status!=1){
                            $('.button').removeAttr('submitting');
                            core.tip.show(rjson.result);
                            return;
                        }
                        location.href =  rjson.result.alipay.url;
                    },true,true);
                 })
           }
           

           
           if(result.credit.success){
               
               $(".order_sub3").click(function(){
                 if($(this).attr('submitting')=='1'){
                     return;
                 }
                 core.tip.confirm('确认要立即付款?',function(){
                    $('.button').attr('submitting',1);
                    core.json('order/pay',{
                        op:'complete',
                        franchise_order_id:'{$_GPC['franchise_order_id']}',
                        type:'credit'
                    },function(pay_json){
                        if(pay_json.status==1){
                           $('#container').html(tpl('tpl_order_pay',pay_json.result));
                           return;
                        }
                        core.tip.show(pay_json.result);
                        $('.button').removeAttr('submitting');
                    },true,true);
               });
                });
           }
           
            if(result.cash.success){
               $(".order_sub6").click(function(){
                   if($(this).attr('submitting')=='1'){
                       return;
                   }
                   core.tip.confirm('确认要货到付款?',function(){
                       $('.button').attr('submitting',1);
                    core.json('order/pay',{
                        op:'complete',
                        franchise_order_id:'{$_GPC['franchise_order_id']}',
                        type:'cash'
                    },function(pay_json){
                        if(pay_json.status==2){
                           $('#container').html(tpl('tpl_order_cash',pay_json.result));
                           return;
                        }
                        core.tip.show(pay_json.result);
                        $('.button').removeAttr('submitting');
                    },true,true);
               });})
           }
           
            if(result.unionpay.success){
         	   
                $('.order_sub7').click(function(){
                	if($(this).attr('submitting')=='1'){
                        return;
                     }
                      $('.button').attr('submitting',1);
                    var deduct = ($('#deductmoney').length>0 &&$('#deductmoney').attr('on')=='1' )?1:0 ;
                   core.json('order/pay', {op: 'pay',type: 'unionpay',franchise_order_id:'{$_GPC['franchise_order_id']}',openid:"{$openid}",deduct:deduct}, function (rjson) {
                       if(rjson.status!=1){
                           $('.button').removeAttr('submitting');
                           core.tip.show(rjson.result);
                           return;
                       }
                       location.href =  rjson.result.url;
                   },true,true);
                })
          }
            
           if(result.wechat.success){
                $('.order_sub1').click(function(){   
                        if($(this).attr('submitting')=='1'){
                           return;
                        }
                         $('.button').attr('submitting',1);
                         var deduct = ($('#deductmoney').length>0 &&$('#deductmoney').attr('on')=='1' )?1:0 ;
                         core.json('order/pay', {op: 'pay',type: 'weixin',franchise_order_id:'{$_GPC['franchise_order_id']}',deduct:deduct}, function (rjson) {
                            if(rjson.status!=1){
                                $('.button').removeAttr('submitting');
                                core.tip.show(rjson.result);
                                return;
                            }
                            
                            var wechat = rjson.result.wechat;
                         
                                require(['http://res.wx.qq.com/open/js/jweixin-1.0.0.js'],function(wx){
                                        jssdkconfig = {php echo json_encode($_W['account']['jssdkconfig']);} || { jsApiList:[] };
                                        jssdkconfig.debug = false;
                                        jssdkconfig.jsApiList = ['checkJsApi','chooseWXPay'];
                                        wx.config(jssdkconfig);
	                      wx.ready(function () {
                                                $('.button').removeAttr('submitting');
                                                 var appid = wechat.appid?wechat.appid:wechat.appId;
                                                wx.chooseWXPay({
                                                    'appId' :  appid,
                                                    'timestamp': wechat.timeStamp,
                                                    'nonceStr' : wechat.nonceStr,
                                                    'package' :  wechat.package,
                                                    'signType' : wechat.signType,
                                                    'paySign' : wechat.paySign,
                                                    success: function (res) {
                                                       
                                                                core.json('order/pay',{
                                                                     op:'complete',
                                                                     franchise_order_id:'{$_GPC['franchise_order_id']}',
                                                                     type:'weixin',deduct:deduct
                                                                 },function(pay_json){
                                                                     if(pay_json.status==1){
                                                                        $('#container').html(tpl('tpl_order_pay',pay_json.result));
                                                                        return;
                                                                     }
                                                                     core.tip.show(pay_json.result);
                                                                     $('.button').removeAttr('submitting');
                                                                 },true,true);
                                                          
                                                    },fail:function(res){
                                                        alert(res.errMsg);
                                                    }
                                                });
                                            });
                              }); 
                          },true,true); 
                 });
             }
             $('.order_subc').click(function(){   
                       core.tip.confirm('确认要立即付款?',function(){
                           $('.button').attr('submitting',1);
                                core.json('order/pay',{
                                       op:'complete',
                                       franchise_order_id:'{$_GPC['franchise_order_id']}',
                                       type:'credit'
                                },function(pay_json){ 
                                    if(pay_json.status==1){
                                       $('#container').html(tpl('tpl_order_pay',pay_json.result));
                                       return;
                                    }
                                    core.tip.show(pay_json.result);
                                    $('.button').removeAttr('submitting');
                                },true,true);
                           })
              });
             
        
    },true)
});
</script>
{template 'common/footer'}